package edu.ufop.vaadin.view;


import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

@SuppressWarnings("serial")
public class WelcomeView extends CustomComponent implements View {

	public static final String NAME = "";


	Label text = new Label();

	Label welcome = new Label();
	

	Button cadastarUsuario = new Button("Cadastrar Professor",
			new Button.ClickListener() {

				@Override
				public void buttonClick(ClickEvent event) {
					
					
					getUI().getNavigator().navigateTo(CadastrarProfessorView.NAME);
					


				}
			});

	Button logout = new Button("Logout", new Button.ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {

			// "Logout" the user
			getSession().setAttribute("user", null);

			// Refresh this view, should redirect to login view
			getUI().getNavigator().navigateTo(NAME);
		}
	});

	public WelcomeView() {

		setCompositionRoot(new CssLayout(welcome, text, logout, cadastarUsuario));
	}

	@Override
	public void enter(ViewChangeEvent event) {
		// Get the user name from the session
		String username = String.valueOf(getSession().getAttribute("user"));

		// And show the username
		text.setValue("Hello " + username);

		welcome.setValue("Bem Vindo ao e-comp");
		

	}


}